#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Repository
// 
// File : BagOfManyToManyRepository.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : BagOfManyToMany Db Action
// 
// History : 
//			2010-09-16 13:20:49	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using JackieHan.NHibernate3.Domain;

#endregion

namespace JackieHan.NHibernate3.Repository
{
    /// <summary> 
    /// BagOfManyToMany Db Action
    /// </summary>
    public class BagOfManyToManyRepository
    {
        public void Save(BagOfManyToMany manyToMany)
        {
            NHSessionFactory.EncloseInTransaction(s => s.Save(manyToMany));
        }

        public void Save(IList<BagOfManyToMany> items)
        {
            using (var session = NHSessionFactory.SessionFactory.OpenSession())
            {
                using (var trans = session.BeginTransaction())
                {
                    try
                    {
                        foreach (BagOfManyToMany item in items)
                        {
                            session.Save(item);
                        }
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        throw;
                    }
                   
                }
            }
        }
    }
}